
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
         let a={url:"www.baidu.com"};
         let b={name:"www.hanguo.com"};

         //属性检测
         //in 不仅检测属性，还会检测是否在原型链上
        //  Object.prototype.url="sassa";
          console.log("url" in a);//true

          //只检测本对象的属性，不看原型链上
          console.log(a.hasOwnProperty("url"));

          //for in 遍历对象
          for (const key in a) {
              if (a.hasOwnProperty(key)) {
                  const element = a[key];
                  console.log(element);
              }
          }
          //如果不用hasOwnProperty遍历就会遍历父级的属性
          //如下
          Object.setPrototypeOf(a,b);
          for (const key in a) {
              console.log(key);
            //url 
            //name  都打印出来了



            //借用call apply
            for (const key in a) {
                if (Object.hasOwnProperty.call(a, key)) {
                    const element = object[key];
                    
                }
            }
          }
    </script>
</body>
</html>